﻿$(function () {
    APrincipalShow();
    BPrincipalShow();
    CPrincipalShow()
});

function APrincipalShow() {
    layui.use(function () {
        // 创建表格实例
        $.ajax({
            url: "/Warehouses/LedgerInfoPrincipalShow",
            type: "get",
            data: {
                selectWarehouseArea: "A区",
            },
            success: function (data) {
                data = JSON.parse(data);
                console.log(data.data);
                // 在 ajax 请求成功后，使用正确的表格 ID 进行 reload
                $(data.data).each(function () {
                    $("#Adistrict").append('<div style="background:#FFFAF0;width:150px; height:100px;float:left;margin:10px;">' +
                        '<p>' + this.warehouseName + '</p>' +
                        '<a class="layui-btn layui-btn-danger layui-btn-xs" onclick="Delete(' + this.warehouseID + ')"><i class="layui-icon layui-icon-Delete"></i>删除</a>' +
                        '<a class="layui-btn layui-btn-danger layui-btn-xs" onclick="Particulars(' + this.warehouseID + ')"><i class="layui-icon layui-icon-edit"></i>详情</a>' +
                        '</div >')
                })
            }
        });
    });
}
//B区
function BPrincipalShow() {
    layui.use(function () {
        // 创建表格实例
        $.ajax({
            url: "/Warehouses/LedgerInfoPrincipalShow",
            type: "get",
            data: {
                selectWarehouseArea: "B区",
            },
            success: function (data) {
                data = JSON.parse(data);
                console.log(data.data);
                // 在 ajax 请求成功后，使用正确的表格 ID 进行 reload
                $(data.data).each(function () {
                    $("#Bdistrict").append('<div style="background:#FFFAF0;width:150px; height:100px;float:left;margin:10px;">' +
                        '<p>' + this.warehouseName + '</p>' +
                        '<a class="layui-btn layui-btn-danger layui-btn-xs" onclick="Delete(' + this.warehouseID + ')"><i class="layui-icon layui-icon-Delete"></i>删除</a>' +
                        '<a class="layui-btn layui-btn-danger layui-btn-xs" onclick="Particulars(' + this.warehouseID + ')"><i class="layui-icon layui-icon-edit"></i>详情</a>' +
                        '</div >')
                })
            }
        });
    });
}
//C区
function CPrincipalShow() {
    layui.use(function () {
        // 创建表格实例
        $.ajax({
            url: "/Warehouses/LedgerInfoPrincipalShow",
            type: "get",
            data: {
                selectWarehouseArea: "C区",
            },
            success: function (data) {
                data = JSON.parse(data);
                console.log(data.data);
                // 在 ajax 请求成功后，使用正确的表格 ID 进行 reload
                $(data.data).each(function () {
                    $("#Cdistrict").append('<div style="background:#FFFAF0;width:150px; height:100px;float:left;margin:10px;">' +
                        '<p>' + this.warehouseName + '</p>' +
                        '<a class="layui-btn layui-btn-danger layui-btn-xs" onclick="Delete(' + this.warehouseID + ')"><i class="layui-icon layui-icon-Delete"></i>删除</a>' +
                        '<a class="layui-btn layui-btn-danger layui-btn-xs" onclick="Particulars(' + this.warehouseID + ')"><i class="layui-icon layui-icon-edit"></i>详情</a>' +
                        '</div >')
                })
            }
        });
    });
}    //删除
window.Delete = function (id) {
    console.log(id);
    layer.confirm('确定要删除该条数据吗？', function (index) {
        $.ajax({
            type: "Post",
            url: "/Warehouses/LedgerInfowarehouseDelete",  // 替换为实际的后台删除数据接口地址
            data: { data: JSON.stringify({ warehouseID: id }), token: localStorage.getItem("token") },
            success: function (res) {
                var res = JSON.parse(res)
                if (res.code >= 1) {
                    layer.alert("删除成功");
                    warehouseShow();  // 重新加载数据，刷新表格显示
                } else {
                    layer.alert("删除失败");

                }
            },
            error: function () {
                layer.msg('删除失败，请稍后重试', {
                    time: 2000,
                    icon: 2
                });
            }
        });
        layer.close(index);
    });
};


//详情
function Particulars(warehouseID) {
    //  localStorage["warehouseID"] = warehouseID
    //  location.href = "/Warehouses/fantian";
    console.log(warehouseID);
}

